<template>
  <div class="product-list">
    <h2>商品列表</h2>
    <div v-for="product in products" :key="product.id" class="product">
      {{ product.name }} - ¥{{ product.price }}
      <button @click="addToCart(product)">加入购物车</button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      products: [
        { id: 1, name: '手机', price: 1000 },
        { id: 2, name: '电脑', price: 2000 },
        { id: 3, name: '键盘', price: 200 }
      ]
    }
  },
  methods: {
    addToCart(product) {
      this.$store.dispatch('cart/addToCart', product)
    }
  }
}
</script>